package k8s

import (
	"fmt"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/api/core/v1"
)

type K8sPersistentVolume struct {
	Name string												`json:"name"`
	Annotation map[string]string							`json:"annotation"`
	Labels map[string]string								`json:"labels"`
	Capacity v1.ResourceList								`json:"capacity"`
	Strategy v1.PersistentVolumeReclaimPolicy				`json:"strategy"`
	AccessModes []v1.PersistentVolumeAccessMode				`json:"accessmodes"`
	Status v1.PersistentVolumePhase							`json:"status"`
	Claim string											`json:"claim"`
	Reason string											`json:"reason"`
	Message string 											`json:"message"`
	Createdate string										`json:"createdate"`
	Source v1.PersistentVolumeSource						`json:"source"`

}

func GetKubernetesPersistentVolumeList()(k8sPvs []K8sPersistentVolume,err error)  {
	pvs,_ := clientset.CoreV1().PersistentVolumes().List(metav1.ListOptions{})
	for _,pv := range pvs.Items {
		k8sPv := K8sPersistentVolume{
			Name: pv.Name,
			Labels: pv.Labels,
			Capacity: pv.Spec.Capacity,
			AccessModes: pv.Spec.AccessModes,
			Status: pv.Status.Phase,
			Claim: fmt.Sprintf("%s/%s",pv.Spec.ClaimRef.Namespace,pv.Spec.ClaimRef.Name),
			Reason: pv.Status.Reason,
			Createdate: pv.CreationTimestamp.Format("2006-01-02"),
		}
		k8sPvs = append(k8sPvs,k8sPv)
	}
	return


}


func GetKubernetesPersistentVolume(name string)(k8sPv K8sPersistentVolume,err error)  {
	pv,_ := clientset.CoreV1().PersistentVolumes().Get(name,metav1.GetOptions{})

	fmt.Println(pv.Spec.PersistentVolumeSource)
		k8sPv = K8sPersistentVolume{
			Name: pv.Name,
			Annotation: pv.Annotations,
			Labels: pv.Labels,
			Capacity: pv.Spec.Capacity,
			Strategy: pv.Spec.PersistentVolumeReclaimPolicy,
			AccessModes: pv.Spec.AccessModes,
			Status: pv.Status.Phase,
			Claim: fmt.Sprintf("%s/%s",pv.Spec.ClaimRef.Namespace,pv.Spec.ClaimRef.Name),
			Message: pv.Status.Message,
			Reason: pv.Status.Reason,
			Createdate: pv.CreationTimestamp.Format("2006-01-02"),
			Source: pv.Spec.PersistentVolumeSource,
		}

	return


}
